clear
clc
close all

% filenames = {'demoStaticTest.txt','demoStaticTest2.txt','demoStaticTest3.txt','demoStaticTest4.txt','demoStaticTest5.txt'};

filenames = {'Group08_08AM_statictest1'};

plotThings = 1;
% tic
nfns = length(filenames);

whandle = waitbar(0,'Simulations Running');
for i = 1:nfns
    
    [dat(i).t,dat(i).x,maxdist(i),maxheight(i),loadtime(i),simTime(i)] = runSim(['staticTestData/' filenames{i}],plotThings);
    waitbar(i/nfns,whandle,'Simulations Running');
    
end
close(whandle);


figure
hold all
maxMaxDist = max(maxdist);
maxMaxHeight = max(maxheight);
axis([0,maxMaxDist,-10,10,0,maxMaxHeight])
for i = 1:nfns
    distVec = sqrt(dat(i).x(:,1).^2+dat(i).x(:,3).^2);
    for j = 1:length(dat(i).x(:,1))
        if distVec(j) > maxdist(i)
            dat(i).x(j,1:3) = [NaN,NaN,NaN];
        end
    end
    
    phandle(i) = plot3(dat(i).x(:,1),dat(i).x(:,3),dat(i).x(:,2));
    ltitle{i} = ['Test ' num2str(i)];
end
legend(phandle,ltitle)
xlabel('x position')
ylabel('z position')
zlabel('y position')
grid on
view([-28 23])
    
% ttime = toc;
ttime = sum(loadtime) + sum(simTime);
fprintf('\n\nTotal run time is %2.1f s\n',ttime)

meanDist = mean(maxdist);
mdFt = meanDist*3.28;
stdDist = std(maxdist);
stdDft = stdDist*3.28;

fprintf('\nMean Dist = %2.1fm (%3.1f ft), while the std dist = %2.1fm (%3.1f ft)\n',meanDist,mdFt,stdDist,stdDft)